﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Platform.ObjectModel.Design;
using Platform.ObjectModel.Serializers;

namespace Platform.ObjectModel.Design
{
	internal static class FieldDescriptorExtensions
	{

		//internal static string GetSerializedValueBase64String( this FieldDescriptor field, object value )
		//{
		//    Arguments.IsNotNull( "field", field );

		//    if ( value == null )
		//        return null;

		//    return field.GetSerializer().SerializeBase64String( value );
		//}


		/// <summary>
		/// Obtém o objeto que realiza a serialização do valor do campo
		/// </summary>
		/// <param name="field"></param>
		/// <returns></returns>
		internal static DataObjectStreamer GetSerializer( this FieldDescriptor field )
		{
			if ( field.FormatterName == null || field.FormatterName.Equals( Globals.Formatters.Native ) )
				return new NativeStreamer();
			else if ( field.FormatterName.Equals( Globals.Formatters.JSon ) )
				return new JavaScriptStreamer();
			else if ( field.FormatterName.Equals( Globals.Formatters.DataObjectName ) )
				return new DataObjectNameStreamer();
			else if ( field.FormatterName.Equals( Globals.Formatters.Token ) )
				return new TokenStreamer();
			else
				throw new NotSupportedException();
		}
	}
}
